<?php
namespace Kxdrmobile\Controller;
use Think\Controller;
class UserController extends ExtendController {
	public function index(){
		$tida_mixnick = I("tida_mixnick");
		cookie("tida_mixnick",$tida_mixnick);
		$this->ajaxReturn();
	}
	public function appname(){
		$appname = I("appname");
		cookie("appname",$appname);
		$this->ajaxReturn();
	}
	public function address(){
		$ADR = D("MainUserAddress");
		$ADR->sid=$this->sid;
		$ADR->uid=$this->uid;
		$address = $ADR->getUserDefaultAddress();

		$this->assign("address",current($address));
		$this->display();
	}
	public function save_addr(){
		$name = I("name");
		$mobile = I("mobile");
		$picker = explode(" ",I("picker"));
		$address = I("address");
		
		$data["sid"]=$this->sid;
		$data["kxdr_uid"]=$this->uid;
		$data["shop_uid"]=$this->shop_uid;
		$data["sys_uid"]=$this->sys_uid;
		$data["nationality"]="中国";
		$data["province"]=$picker[0];
		$data["city"]=$picker[1];
		$data["city_part"]=$picker[2];
		$data["address"]=$address;
		$data["name"]=$name;
		$data["tel"]=$mobile;
		$data["is_def"]=true;
			
		$ADR = D("MainUserAddress");
		$ADR->sid=$this->sid;
		$ADR->uid=$this->uid;
		$ADR->save_data=$data;
		$re = $ADR->saveAddress();
		
		$this->ajaxReturn($re);
	}
	public function collect_item(){
		$item_iid = I("iid");
		$COLL = M("UserGiftsItemcollect");
		$coll["sid"]=$this->sid;
		$coll["user_id"]=$this->uid;
		$coll["item_iid"]=$item_iid;
		$coll["is_collect"]=true;
		$coll["add_time"]=date("Y-m-d H:i:s");
		$re = $COLL->add($coll);
		$this->ajaxReturn(Array("hasError"=>!$re));
	}
	public function addcart_item(){
		$item_iid = I("iid");
		$COLL = M("UserGiftsItemaddcart");
		$coll["sid"]=$this->sid;
		$coll["user_id"]=$this->uid;
		$coll["item_iid"]=$item_iid;
		$coll["is_addcart"]=true;
		$coll["add_time"]=date("Y-m-d H:i:s");
		$re = $COLL->add($coll);
		$this->ajaxReturn(Array("hasError"=>!$re));
	}
}